﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Service;

namespace community
{
    public partial class familyrelation : Form
    {
        public familyrelation()
        {
            InitializeComponent();
        }

        private void familyrelation_Load(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
            textBox8.Text = "";
            textBox9.Text = "";
            textBox10.Text = "";
            textBox11.Text = "";
            comboBox1.Text = "";
            textBox1.Text = family.datagridviewJMXM ;
            textBox2.Text = family.datagridviewXB ;
            textBox3.Text = family.datagridviewCSRQ;
            textBox4.Text = family.datagridviewSFZH;
            textBox9.Text = family.datagridviewYHZGX;
            textBox10.Text = family.datagridviewJMBH;
            string hzbh = family.residentBH;
            string sql = " select inhabitantcode_chr as 户主编号, residentname_chr as 户主姓名,sex_chr as 户主性别,birth_dat as 出生日期,identitycard_chr as 身份证号 from T_CS_INHABITANTRECORD_NEW  where inhabitantcode_chr='"+hzbh+"'";
            Cls_DBHelper help = new Cls_DBHelper();
            SqlDataReader dr = help.m_clsGetReader(sql);
            if (dr.Read())
            {
                textBox5.Text = dr["户主姓名"].ToString();
                textBox6.Text = dr["户主性别"].ToString();
                textBox7.Text = dr["出生日期"].ToString();
                textBox8.Text = dr["身份证号"].ToString();
                textBox11.Text = dr["户主编号"].ToString();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(comboBox1.Text=="")
            {
                MessageBox.Show("请输入家庭成员新的与户主关系", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            string sql = "update T_CS_INHABITANTRECORD_NEW set rehouseholder_vchr='" + Convert.ToString(comboBox1.Text.Trim()) + "' where inhabitantcode_chr='" + family.datagridviewJMBH+"'";
            SqlConnection cn = new SqlConnection(SQL.conStr);
            cn.Open();
            SqlCommand cm = new SqlCommand(sql,cn);
            cm.ExecuteNonQuery();
            cn.Close();
            MessageBox.Show("修改与户主关系成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
    }
}
